package com.example.community.dao;

import com.example.community.mapper.ComtyMapper;
import com.example.community.mapper.ParkingMapper;
import com.example.community.model.Comty;
import com.example.community.model.Parking;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * 小区表
 */
public class ComtyDao {
    public Comty fandById(Integer id){
        try (SqlSession session = MybatisUtil.getSession()){
            final ComtyMapper mapper = session.getMapper(ComtyMapper.class);
            return mapper.selectByPrimaryKey(id);
        }
    }

    public List<Comty> fandByAll(){
        try (SqlSession session = MybatisUtil.getSession()){
            final ComtyMapper mapper = session.getMapper(ComtyMapper.class);
            return mapper.selectAll();
        }
    }

    public List<Comty> fandLimit(Integer ys, Integer shuju){
        try (SqlSession session = MybatisUtil.getSession()){
            final ComtyMapper mapper = session.getMapper(ComtyMapper.class);
            Integer yss =(ys - 1) * shuju;
            return mapper.selectLimit(yss,shuju);
        }
    }

    public Integer selectLimitCount(Integer pageSize){
        try (SqlSession session = MybatisUtil.getSession()){
            final ComtyMapper mapper = session.getMapper(ComtyMapper.class);
            int count = mapper.CountComty();
            return (count + pageSize - 1)/pageSize;
        }
    }
}
